package com.test.io.buffer;

import org.junit.Test;

import java.io.*;

/**
 * @version 1.0
 * @Author: 许啸林 使用处理流 复制文本文件 (字符流不能处理二进制文件 图片音视频等文件)
 * @Date: 2021/6/2 16:50
 */
public class BuffCopyFile {
    @Test
    public void buffCopyFile() {
        String oldFilePath = "d:\\newFile2.text";
        String targerFilePath = "d:\\buffCopy.text";
        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader(oldFilePath));
            writer = new BufferedWriter(new FileWriter(targerFilePath));
            String readData = "";
            while((readData = reader.readLine()) != null) {
                writer.write(readData);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(reader != null) {
                    reader.close();
                }
                if(writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
